package com.ys.web.mobao.controller;

import com.ys.web.mobao.service.MobaoWithholdingService;
import com.ys.web.pay.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/onlinePay/transferDomestic/account/")
public class MobaoWalletController {
    @Autowired
    private PayService payService;
    @Autowired
    private MobaoWithholdingService mobaoWithholdingService;
//
//    /**
//     * 提现预下单
//     *
//     * @param withholdingCreate
//     * @return
//     */
//    @RequestMapping("create")
//    public String create(@RequestAttribute String ip, MobaoWithholdingCreate withholdingCreate) {
//        if(!withholdingCreate.getRemark().equals(DateUtil.getYYMMDD())){
//            SystemError.wrapBs("500","用户错误");
//        }
//        withholdingCreate.setAmount(StringHandler.getString(StringHandler.yuanToFen(withholdingCreate.getAmount())));
//        withholdingCreate.setArrivalAmount(withholdingCreate.getAmount());
//        // 银行卡提现操作
//        try {
//            UserBank userBank = new UserBank();
//            userBank.setUserName(Config.pp.get("wallet.withholding.user.name"));
//            userBank.setCardNo(Config.pp.get("wallet.withholding.user.card"));
//            JSONObject data = MobaoPay.withdraw(ip,"key",withholdingCreate,userBank);
//            if(data.getString("orderStatus").equals("00")){
//                return ResponseHandler.success();
//            }else if(data.getString("orderStatus").equals("09")){
//                return ResponseHandler.success();
//            } else {
//                SystemError.wrapBs("400","提现失败,请核对并修改正确的信息后再试");
//            }
//        } catch (Exception e) {
//            Logger.error("提现失败:",e);
//            SystemError.wrapBs("400","提现失败，请核对并修改正确的信息后再试.");
//        }
//        return ResponseHandler.success();
//    }success

//    /**
//     * 提现审核打款
//     *
//     * @param id
//     * @return
//     */
//    @RequestMapping("waitAgree")
//    public String waitAgree(String id) {
//        if(StringHandler.isEmpty(id)){
//            return ResponseHandler.error("500","参数传递错误");
//        }
//        WithdrawRecordWait record = mobaoWithholdingService.getWithdrawRecordWaitById(id);
//        if(StringHandler.isEmpty(record)){
//            SystemError.wrapBs("500","该笔审核不存在");
//        }
//        if(!record.getWithdrawStatus().equals(PayEnum.WithdrawWaitStatus.APPLY_WITHDRAWAL.getCode())){
//            SystemError.wrapBs("500","该笔审核已审核");
//        }
//        int row = payService.updateStatus(id);
//        if (row != 1) {
//            SystemError.wrapBs("500", "操作失败,请联系技术，请勿重复点击通过");
//        }
//        MobaoWithholdingCreate withholdingCreate = new MobaoWithholdingCreate();
//        withholdingCreate.setAmount(StringHandler.getString(record.getWithdrawAmount()));
//        withholdingCreate.setArrivalAmount(withholdingCreate.getAmount());
//        withholdingCreate.setRequestId(record.getOrderNo());
//
//        UserBank userBank = payService.getUserBankByUserId(record.getUserId(), record.getCardToken());
//        record.setWithdrawStatus(PayEnum.WithdrawStatus.APPLY_WITHDRAWAL.getCode());
//        try{
//            // 银行卡提现操作
//            MobaoPay.withdraw(record.getIp(),"key",withholdingCreate,userBank);
//        }catch (Exception ignored){
//
//        }
//        row = mobaoWithholdingService.updateWithdrawRecordWaitByOrderId(record);
//        if (row != 1) {
//            SystemError.wrapBs("500", "操作失败,请联系技术，请勿重复点击通过");
//        }
//        return ResponseHandler.success();
//    }
}
